<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>消息</title>

    <style>
        html{
            background-image: url("img/messageback.jpg");
            background-repeat: no-repeat;
            background-size: cover;
        }
        .mycard{
            margin-left: 10px;
            margin-bottom: 15px;
            padding: 24px 18px;
            background-color: white;
            -webkit-box-shadow: 0 2px 4px 0 rgb(121 146 185);
            box-shadow: 0 2px 4px 0 rgb(121 146 185);
            border-radius: 4px;
            overflow: hidden;
            text-overflow: ellipsis;
            word-break: break-word;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            font-size: 16px;
            line-height: 18px;
        }
        .mycard .form{
            margin-bottom: 10px;
        }
        .mycard .content{
            margin-bottom: 10px;
        }
        .mycard .time{
            margin-top: 10px;
            font-size: 10px;
            color: gray;
        }
    </style>
</head>
<body>
<div id="app">
    <div class="head" style="margin-top:10px;background-image: linear-gradient(to right, #6a11cb 0%, #2575fc 100%);color: white;font-size: large;margin-bottom: 10px">
        目前共有 {{list_len}} 条消息
    </div>
    <div class="mycard" v-for="item in message.list" :key="item.u_name" style="font-family: Arial, Helvetica, sans-serif;">
        <div class="form">用户 <b>{{item.u_name}}</b> 发来了一条消息</div>
        <div class="content">{{item.message}}</div>
        <div class="time" style="font-family:Times New Roman, Times, serif;">{{item.time}}</div>
    </div>
</div>
<script src="js/jquery-3.6.0.slim.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/vue.global.js"></script>
<script src="js/axios.min.js"></script>
<script src="js/my-axios.js"></script>
<script src="layer/layer.js"></script>

<script>
    const app = {
        data() {
            return{
                message:{},

                list_len:0
            };
        },

        methods: {
            showMessage(){
                const loadIdx = layer.load(0, {
                    success: () => {//等待加载提示显示出来后，再加载数据，这样可以避免加载提示一直在转圈圈。
                        //加载数据
                        myAxios.get('/showMessage').then((response) => {
                            this.message = response.data.data;
                            console.log(this.message)
                            this.list_len = this.message.list.length
                            layer.close(loadIdx);
                        }).catch(err => {
                            layer.close(loadIdx);
                        }).finally(() => {
                            layer.close(loadIdx);
                        });
                    }
                });
            }

        },

        mounted() {
            this.showMessage();
        }

    };

    Vue.createApp(app).mount('#app')

</script>
</body>
</html>